/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "../Button.h"
#include "Button.h"
#include <xml/Stream.h>

namespace liba
{
namespace lib2d
{
namespace gui
{
namespace view
{

Button::Button( gui::Button * obj )
:	Object( obj ),
	obj( obj )
{}

void Button::render( hard::Renderer * rend )
{
	if( !image )
		return Object::render( rend );

	if( obj->is_pressed() )
		pressed.render( rend, image, obj->get_window_rect().width, obj->get_window_rect().height );
	else
		if( obj->is_mouse_over() )
			over.render( rend, image, obj->get_window_rect().width, obj->get_window_rect().height );
		else
			normal.render( rend, image, obj->get_window_rect().width, obj->get_window_rect().height );

	Object::render( rend );
}

bool Button::on_attribute( xml::Provider * prov, const std::string & name, const std::string & value )
{
	if( name == "Image" )
	{
		image = new objects::ImageSimple( value );
		return true;
	}
	return false;
}

bool Button::on_node( xml::Provider * prov, const std::string & name )
{
	if( name == "Normal" )
		return prov->parse_object( &normal );
	if( name == "Pressed" )
		return prov->parse_object( &pressed );
	if( name == "Over" )
		return prov->parse_object( &over );
	return false;
}

} //namespace view
} //namespace gui
} //namespace lib2d
} //namespace liba

